package com.woniu.util;

import com.woniu.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Component
public class SessionUtil {
    private static HttpServletRequest request;

    @Autowired
    public SessionUtil(HttpServletRequest request) {
        SessionUtil.request = request;
    }

    private static HttpSession getSession() {
        return request.getSession();
    }

    public static void setAttribute(String name, Object value) {
        getSession().setAttribute(name, value);
    }

    public static Object getAttribute(String name) {
        return getSession().getAttribute(name);
    }

    public static Employee getEmployee() {
        return (Employee) getSession().getAttribute("employee");
    }

    public static void removeAttribute(String name) {
        getSession().removeAttribute(name);
    }

    public static void invalidate() {
        getSession().invalidate();
    }
}